home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / ghostscript / src / gxcldev.h < prev    next >
C/C++ Source or Header  |  1994-08-01  |  5KB  |  129 lines

  1. /* Copyright (C) 1991, 1992, 1993 Aladdin Enterprises.  All rights reserved.
  2.  
  3. This file is part of Ghostscript.
  4.  
  5. Ghostscript is distributed in the hope that it will be useful, but
  6. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  7. to anyone for the consequences of using it or for whether it serves any
  8. particular purpose or works at all, unless he says so in writing.  Refer
  9. to the Ghostscript General Public License for full details.
  10.  
  11. Everyone is granted permission to copy, modify and redistribute
  12. Ghostscript, but only under the conditions described in the Ghostscript
  13. General Public License.  A copy of this license is supposed to have been
  14. given to you along with Ghostscript so you can know your rights and
  15. responsibilities.  It should be in a file named COPYING.  Among other
  16. things, the copyright notice and this notice must be preserved on all
  17. copies.  */
  18.  
  19. /* gxcldev.h */
  20. /* Internal definitions for Ghostscript command lists. */
  21. #include "gxclist.h"
  22.  
  23. #define cdev ((gx_device_clist *)dev)
  24.  
  25. /* A command always consists of an operation followed by operands. */
  26. /* The operands are implicit in the procedural code. */
  27. /* Operands marked # are variable-size. */
  28. typedef enum {
  29.     cmd_op_misc = 0x00,        /* (see below) */
  30.       cmd_opv_end_run = 0x00,    /* (nothing) */
  31.       cmd_opv_set_tile_size = 0x01,    /* width#, height# */
  32.       cmd_opv_set_tile_phase = 0x02, /* x#, y# */
  33.     cmd_op_set_color0 = 0x10,    /* color+2 in op byte | color# */
  34.     cmd_op_set_color1 = 0x20,    /* color+2 in op byte | color# */
  35.     cmd_op_set_tile_index = 0x30,    /* index */
  36.     cmd_op_fill_rect = 0x40,    /* rect# */
  37.     cmd_op_fill_rect_short = 0x50,    /* dh in op byte,dx,dw | rect_short */
  38.     cmd_op_fill_rect_tiny = 0x60,    /* dw in op byte, rect_tiny */
  39.     cmd_op_tile_rect = 0x70,    /* rect# */
  40.     cmd_op_tile_rect_short = 0x80,    /* dh in op byte,dx,dw | rect_short */
  41.     cmd_op_tile_rect_tiny = 0x90,    /* dw in op byte, rect_tiny */
  42.     cmd_op_copy_mono = 0xa0,    /* rect#, data_x#, raster# | */
  43.                     /* d_x+1 in op byte, x#, y#, w, h */
  44.     cmd_op_copy_color = 0xb0,    /* rect#, data_x#, raster# */
  45.     cmd_op_set_tile_bits = 0xc0,    /* index, <bits> */
  46.     cmd_op_delta_tile_bits = 0xd0,    /* n-1 in op byte, n x <offset, bits> */
  47.     cmd_op_end
  48. } gx_cmd_op;
  49.  
  50. #define cmd_op_name_strings\
  51.   "misc", "set_color_0", "set_color_1", "set_tile",\
  52.   "fill_rect", "fill_rect_short", "fill_rect_tiny", "tile_rect",\
  53.   "tile_rect_short", "tile_rect_tiny", "copy_mono", "copy_color",\
  54.   "set_tile_bits", "delta_tile_bits", "?e0?", "?f0?"
  55.  
  56. #define cmd_misc_op_name_strings\
  57.   "end_run", "set_tile_size", "set_tile_phase", "?03?",\
  58.   "?04?", "?05?", "?06?", "?07?",\
  59.   "?08?", "?09?", "?0a?", "?0b?",\
  60.   "?0c?", "?0d?", "?0e?", "?0f?"\
  61.  
  62. #ifdef DEBUG
  63. extern const char *cmd_op_names[16];
  64. extern const char *cmd_misc_op_names[16];
  65. #endif
  66.  
  67. /* Define the size of the largest command, not counting any bitmap. */
  68. #define cmd_tile_d 3            /* size of tile delta */
  69. /* The variable-size integer encoding is little-endian.  The low 7 bits */
  70. /* of each byte contain data; the top bit is 1 for all but the last byte. */
  71. #define cmd_max_intsize(siz)\
  72.   (((siz) * 8 + 6) / 7)
  73. #define cmd_largest_size\
  74.   max(1 + 6 * cmd_max_intsize(sizeof(int)) /* copy_mono */, 2 + 16 * cmd_tile_d /* delta_tile 15 */)
  75.  
  76. /* Define command parameter structures. */
  77. typedef struct {
  78.     int x, y, width, height;
  79. } gx_cmd_rect;
  80. typedef struct {
  81.     byte dx, dwidth, dy, dheight;    /* dy and dheight are optional */
  82. } gx_cmd_rect_short;
  83. #define cmd_min_short (-128)
  84. #define cmd_max_short 127
  85. typedef struct {
  86.     unsigned dx : 4;
  87.     unsigned dy : 4;
  88. } gx_cmd_rect_tiny;
  89. #define cmd_min_tiny (-8)
  90. #define cmd_max_tiny 7
  91.  
  92. /* Define the prefix on each command run in the writing buffer. */
  93. typedef struct cmd_prefix_s cmd_prefix;
  94. struct cmd_prefix_s {
  95.     cmd_prefix *next;
  96.     uint size;
  97. };
  98.  
  99. /* Define the entries in the block file. */
  100. typedef struct cmd_block_s {
  101.     int band;
  102.     long pos;            /* starting position in cfile */
  103. } cmd_block;
  104.  
  105. /* Remember the current state of one band when writing or reading. */
  106. struct gx_clist_state_s {
  107.     gx_color_index color0, color1;    /* most recent colors */
  108.     tile_slot *tile;        /* most recent tile */
  109.     gs_int_point tile_phase;    /* most recent tile phase */
  110.     gx_cmd_rect rect;        /* most recent rectangle */
  111.     /* Following are only used when writing */
  112.     cmd_prefix *head, *tail;    /* list of commands for band */
  113. };
  114. static tile_slot no_tile = { ~0L };
  115.  
  116. /* The initial values for a band state */
  117. static const gx_clist_state cls_initial =
  118.    {    gx_no_color_index, gx_no_color_index, &no_tile,
  119.      { 0, 0 }, { 0, 0, 0, 0 },
  120.     0, 0
  121.    };
  122.  
  123. #define clist_write(f, str, len)\
  124.   fwrite(str, 1, len, f)
  125.  
  126. /* Define the size of the command buffer used for reading. */
  127. /* This is needed to split up very large copy_ operations. */
  128. #define cbuf_size 500
  129.